﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using Ionic.Zip;
using AI.Fuzzy.Library;


namespace TAI
{
    public partial class _Default : System.Web.UI.Page
    {
        public XML.ManejadorXML manejador;
        string ruta = "";
        string dirActual = "";
        Examen ex;
        

        protected void Page_Load(object sender, EventArgs e)
        {
            
        }

        protected void leerXML(object sender, EventArgs e)
        {
            
            if (archivo.PostedFile.ContentLength > 0)
            {
                try
                {
                    string uploadedFile = Path.GetFileName(archivo.PostedFile.FileName);
                    string location = Server.MapPath("~/ZipFiles/" + uploadedFile);
                    archivo.SaveAs(location);

                    ZipFile fileToExtract = ZipFile.Read(location);
                    fileToExtract.ExtractAll(Server.MapPath("~/UnzippedFiles"), ExtractExistingFileAction.OverwriteSilently);
                    manejador = new XML.ManejadorXML(Server.MapPath("~/UnzippedFiles/datos.xml"));
                    Session["admin"] = manejador;
                    llenarDropDown(manejador.getCategorias());
                    DropDownList1.Visible = true;
                    l2.Text = "Por favor escoja la categoría deseada:";
                    l2.Visible = true;
                    if (ex.stop == true) {
                        l2.Visible = false;
                    }

                }
                catch (Exception exc)
                {
                    System.Diagnostics.Debug.WriteLine("Error saving file <b>" +
                                      ruta + "</b><br />" + exc.ToString() + ".");
                }
            }
        }
        
        private void llenarDropDown(string[] p)
        {
            for (int i = 0; i < p.Length; i++)
            {
                DropDownList1.Items.Add(p[i]);
                Button2.Visible = true;
            }
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            if (Session["admin"] != null)
            {
                manejador = (XML.ManejadorXML)Session["admin"];
                manejador.catActual = DropDownList1.SelectedIndex;
            }
            Response.Redirect("Examen.aspx");
        }

    }
}
